﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace PharmacyPharnet.UserControls
{
    public partial class UCTextBox : ButtonEdit
    {
        #region Declarations
        private int msgMaxLength = 0;
        #endregion
        public UCTextBox()
        {
            InitializeComponent();

            btnText = new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph);
            btnText.Appearance.BackColor = System.Drawing.Color.Cyan;
            btnText.Appearance.ForeColor = System.Drawing.Color.Red;
            btnText.Appearance.BackColor2 = System.Drawing.Color.Transparent;
            btnText.Width = 30;
            btnText.Appearance.Options.UseFont = true;
            btnText.Appearance.Options.UseForeColor = true;

            this.Properties.Buttons.Add(btnText);
            this.Properties.ButtonsStyle = DevExpress.XtraEditors.Controls.BorderStyles.Office2003;
            this.Properties.Appearance.Options.UseBackColor = true;
            this.Properties.Appearance.BackColor = System.Drawing.Color.Transparent;
            this.Properties.Appearance.BackColor2 = System.Drawing.Color.Transparent;

            msgMaxLength = Properties.MaxLength;
            btnText.Caption = msgMaxLength.ToString();
            this.EditValueChanging += new DevExpress.XtraEditors.Controls.ChangingEventHandler(UCTextBox_EditValueChanging);

        }

        void UCTextBox_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
        {
            if (e.NewValue.ToString().Length <= Properties.MaxLength)
                msgMaxLength--;
            btnText.Caption = msgMaxLength.ToString();
        }
    }
}
